import React, { useState, useEffect } from 'react';
import { useNavigate, Outlet } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { selectUser, } from '../redux/Slice/userSlice'
import config from "../Config"
export default () => {
  let user = useSelector(selectUser);
  let navigate = useNavigate();
  useEffect(() => {
    if (!config.isDev) {
      if (user != null && (window.location.pathname == "/" || window.location.pathname == "/login"))
        navigate("/pages");
      if (user == null || window.location.pathname == "/")
        navigate("/login");
    }

  }, [])
  return (<Outlet />)
}